package com.miao.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.miao.common.entity.pojo.Address;
import com.miao.shop.dao.ShopAddressDao;
import com.miao.shop.service.ShopAddressService;
import org.springframework.data.annotation.Transient;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 收货地址表(Address)表服务实现类
 *
 * @author MiaoWenQing
 * @since 2021-02-14 23:09:49
 */
@Service
public class ShopAddressServiceImpl extends ServiceImpl<ShopAddressDao, Address> implements ShopAddressService {


    @Resource
    private  ShopAddressDao shopAddressDao;

    /**
     * 设置默认 地址
     *
     * @return boolean
     */
    @Override
    @Transactional
    public boolean setDefault(String cusId,String addrId) {

        QueryWrapper<Address> addressQueryWrapper = new QueryWrapper<>();
        addressQueryWrapper.eq("cus_id",cusId);
        addressQueryWrapper.eq("addr_type",1);
        Address address1 = this.shopAddressDao.selectOne(addressQueryWrapper);
        if(null!=address1){
            address1.setAddrType(false);
            this.shopAddressDao.updateById(address1);
        }





        Address address = this.shopAddressDao.selectById(addrId);
        address.setAddrType(true);
        this.shopAddressDao.updateById(address);


        return true;
    }
}
